package com.example.footballsystem.service;

import com.example.footballsystem.entity.Master;
import com.example.footballsystem.entity.masterDairy;
import com.example.footballsystem.mapper.MasterAccountMapper;
import com.example.footballsystem.mapper.MasterDairyMapper;
import com.example.footballsystem.mapper.UserDairyMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

@Slf4j
@Service
public class MasterService {
    @Autowired
    MasterAccountMapper masterAccountMapper;
    @Autowired
    MasterDairyMapper masterDairyMapper;
    public boolean Logincheck(String account,String password){
        if(masterAccountMapper.getPassword(account)==null){
            return false;
        } else if (password.equals(masterAccountMapper.getPassword(account))) {

            masterDairy dairy = new masterDairy();
            Timestamp time = new Timestamp(System.currentTimeMillis());

            dairy.setMaster(masterAccountMapper.getAccount(account));
            dairy.setLogintime(time);
            masterDairyMapper.addMasterDairy(dairy);

            return true;
        }else{
            return false;
        }
    }

    //注册
    public boolean regist(Master master){
        if(masterAccountMapper.getAccount(master.getAccount())==null){
            Timestamp time = new Timestamp(System.currentTimeMillis());
            masterAccountMapper.setCreateTime(time, master.getAccount());
            masterAccountMapper.addMaster(master);
            return true;
        }else {
            return false;
        }
    }
}
